<template>
  <div>
    <el-container>
      <!--      <el-aside width="5%"></el-aside>-->
      <el-main class="register-main"
               style="margin-bottom: 10px;width: 400px;height:100%;vertical-align: center">
        <h1 style="color: #409EFF;text-align: center">添加工作人员信息</h1>

        <el-form :model="worker" label-width="20%">
          <el-form-item label="姓名">
            <el-input v-model="worker.userName" type="text" autocomplete="off" placeholder="请输入工作人员姓名" clearable
                      size="medium" style="width: 90%"></el-input>
          </el-form-item>
          <el-form-item label="性别" required>
            <el-select v-model="gender" placeholder="请选择性别" style="width: 90%">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="电话" required>
            <el-input v-model="worker.phone" type="tel" autocomplete="off" placeholder="请输入工作人员的电话" clearable
                      size="medium" style="width: 90%"></el-input>
          </el-form-item>
          <el-form-item label="身份证号" required>
            <el-input v-model="worker.idCard" type="email" autocomplete="off" placeholder="请输入工作人员的身份证号" clearable
                      size="medium" style="width: 90%"></el-input>
          </el-form-item>
          <el-form-item label="生日" required>
            <el-input v-model="worker.birthday" type="date" autocomplete="off" placeholder="请输入工作人员的生日日期" clearable
                      size="medium" style="width: 90%"></el-input>
          </el-form-item>
          <el-form-item label="雇用日期" required>
            <el-input v-model="worker.hireDate" type="date" autocomplete="off" placeholder="请输入工作人员的雇用日期" clearable
                      size="medium" style="width: 90%"></el-input>
          </el-form-item>
          <el-form-item label="辞职日期" required>
            <el-input v-model="worker.resignDate" type="date" autocomplete="off" placeholder="请输入工作人员的辞职日期" clearable
                      size="medium" style="width: 90%"></el-input>
          </el-form-item>
          <el-form-item label="描述" required>
            <el-input v-model="worker.description" type="text" autocomplete="off" placeholder="请输入工作人员的描述" clearable
                      size="medium" style="width: 90%"></el-input>
          </el-form-item>

          <el-form-item label-width="0">
            <el-button type="primary" @click="add()" style="margin-left: 20%;width:100px">添加</el-button>
            <div class="clearBox"></div>
          </el-form-item>
        </el-form>
      </el-main>
      <!--      <el-aside width="5%"></el-aside>-->
    </el-container>
  </div>
</template>

<script>
export default {
  name: "AddWorker",
  data() {
    return {
      worker: {
        userName: "",
        gender:"",
        idCard: "",
        phone: "",
        birthday:"",
        hireDate:"",
        resignDate:"",
        description:"",
        imgsetDir:"",
        profilePhoto:"",
      },
      gender:"",
      options: [{
        value: '选项1',
        label: '男'
      }, {
        value: '选项2',
        label: '女',
      }, {
        value: '选项3',
        label: '其他',
      }],
    }
  },
  watch: {
    gender(newName){
      if(newName == "选项1"){
        this.worker.gender = "男";
      }
      else if(newName == "选项2") {
        this.worker.gender = "女";
        //print(111);
      }
      else if(newName == "选项3") {
        this.worker.gender = "其他";
        //print(111);
      }
    }
  },
  created() {
    if (this.$route.params.isReload == 'true') {
      this.$router.go(0);
    }
  },
  methods: {
    add: function(){
      const _this = this;
      //alert(_this.elder.checkOutDate);
      this.$axios.post('employee/add', {
            "userName": _this.worker.userName,
            "gender": _this.worker.gender,
            "idCard": _this.worker.idCard,
            "phone": _this.worker.phone,
            "birthday": _this.worker.birthday,
            "hireDate": _this.worker.hireDate,
            "resignDate": _this.worker.resignDate,
            "description": _this.worker.description,
            "imgsetDir": _this.worker.imgsetDir,
            "profilePhoto": _this.worker.profilePhoto,
          },
          {
            headers: {
              "Content-Type": "application/json;charset=utf-8"
            },
            withCredentials: true
          }
      ).then(function (response) {

        // 这里是处理正确的回调
        if (response.data.code == '0') {
          _this.$message({
            message: '添加成功！',
            type: 'success'
          });
          _this.$router.go(0);
        } else {
          _this.$message.error(response.data.msg);
        }
      }).catch(function (response) {
        // 这里是处理错误的回调
        console.log(response)
      });
    },

    changePassword: function(){
      this.ChangePasswordFlag = true;
    },
    handleClose(done) {
      done();
    }
  }

}
</script>

<style scoped>

</style>
